//
//  ViewController.m
//  AddShoppingCartDemo
//
//  Created by Jim1024 on 2016/12/23.
//  Copyright © 2016年 Jim1024. All rights reserved.
//

#import "ViewController.h"
#import "GoodsChooseView.h"

@interface ViewController ()

@property (nonatomic, strong) GoodsChooseView *choseView;

@property (nonatomic, strong) NSArray *sizeArr;
@property (nonatomic, strong) NSArray *colorArr;
@property (nonatomic, strong) NSDictionary *stockDict;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    _sizeArr = [[NSArray alloc] initWithObjects:@"S",@"M",@"L",nil];
    _colorArr = [[NSArray alloc] initWithObjects:@"蓝色",@"红色",@"湖蓝色",@"咖啡色",nil];
    NSString *str = [[NSBundle mainBundle] pathForResource: @"stock" ofType:@"plist"];
    _stockDict = [[NSDictionary alloc] initWithContentsOfURL:[NSURL fileURLWithPath:str]];
    
    [self initChoseViewSizeArr:_sizeArr andColorArr:_colorArr andStockDic:_stockDict];
}


/**
 *  初始化弹出视图
 */
-(void)initChoseViewSizeArr:(NSArray *)sizeArr andColorArr:(NSArray *)colorArr andStockDic:(NSDictionary *)stockDic;
{
    //选择尺码颜色的视图
    _choseView = [[GoodsChooseView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
    [self.view addSubview:_choseView];
    [_choseView.cancleBtn addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
    [_choseView.sureBtn addTarget:self action:@selector(sure) forControlEvents:UIControlEventTouchUpInside];
    [_choseView initTypeViewWithSizeArr:_sizeArr colorArr:_colorArr stockDic:_stockDict];
    //点击黑色透明视图choseView会消失
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)];
    [_choseView.maskView addGestureRecognizer:tap];
}

- (IBAction)show:(id)sender {
    [UIView animateWithDuration:0.25 animations:^{
        self.choseView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    }];
}

- (void)dismiss {
    [UIView animateWithDuration:0.25 animations:^{
        self.choseView.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height);
    }];
}

-(void)sure {
    [self dismiss];
    [self showAlert:@"已经加入购物车"];
}

-(void)showAlert:(NSString *)message {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
    [alert show];
}

@end
